package com.erp.framework.util.excelupload;

import java.sql.Timestamp;

import org.apache.poi.hssf.usermodel.HSSFCell;

import com.erp.framework.util.CommonUtil;

public class ExcelIOUtil {
	
	public static Object readValueFromCell(HSSFCell cell, String destType) {
		Object resultValue = null;
        if(cell!=null){
        	switch (cell.getCellType()) {
    		case HSSFCell.CELL_TYPE_BLANK:
    			resultValue = null;
    			break;
    		case HSSFCell.CELL_TYPE_NUMERIC:
    			if ("Date".equalsIgnoreCase(destType)) {
    				resultValue = CommonUtil.dateToString(cell.getDateCellValue());
    			} else {
    				resultValue = CommonUtil.bigDecimalToStr(new java.math.BigDecimal(cell.getNumericCellValue()));
    			}
    			break;
    		case HSSFCell.CELL_TYPE_STRING:
    			resultValue = cell.getStringCellValue().toString().trim();
    			break;
    		case HSSFCell.CELL_TYPE_FORMULA:
    			Double cellValue = new Double(cell.getNumericCellValue());
    			if (cellValue.isNaN()) {
    				resultValue = new Double(0.0);
    			} else {
    				resultValue = cellValue;
    			}
    			break;
    		default:
    			resultValue = cell.getDateCellValue();
    		}
        }
		return resultValue;
	}
	
	public static String getCurrentTimeId(){
		String timestamp = "";
		timestamp = new Timestamp(System.currentTimeMillis()).toString();
		
		timestamp = CommonUtil.stringRpl(timestamp, "-", "");
		timestamp = CommonUtil.stringRpl(timestamp, " ", "");
		timestamp = CommonUtil.stringRpl(timestamp, ":", "");
		timestamp = CommonUtil.stringRpl(timestamp, ".", "");
		return timestamp;
	}
}
